/*
 * DayTask.java
 * Copyright (c) 2011,融众网络技术有限公司(www.11186.com)
 * All rights reserved.
 * ---------------------------------------------------------------------
 * 2011-8-20 Created
 */
package com.rongzhong.time;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.List;

import com.rongzhong.core.logger.SimpleLogger;
import com.rongzhong.time.annotation.Day;
import com.rongzhong.time.base.Task;

/**
 * 
 * @author wufei
 * @version 1.0 2011-8-20
 * @since 1.0
 */
public class DayTask {

	SimpleLogger logger = SimpleLogger.getLogger(this.getClass());

	public List<Task> taskList;;

	public void run() {
		for (Task task : taskList) {
			task.initialize();
			this.runMethod(task, task.getClass().getMethods());
		}
	}

	public void runMethod(Task tasks, Method[] methods) {
		for (Method method : methods) {
			if (method.isAnnotationPresent(Day.class)) {
				try {
					method.invoke(tasks, new Object[0]);
				} catch (IllegalArgumentException e) {
					logger.error(" runMethod IllegalArgumentException ", e);
				} catch (IllegalAccessException e) {
					logger.error(" runMethod IllegalAccessException ", e);
				} catch (InvocationTargetException e) {
					logger.error(" runMethod InvocationTargetException ", e);
				}
			}
		}
	}

	public void setTaskList(List<Task> taskList) {
		this.taskList = taskList;
	}

}
